//
//  UIBarButtonItem+Extension.m
//  实验
//
//  Created by mac on 16/2/29.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"

@implementation UIBarButtonItem (Extension)

+(instancetype)setupNavBarBtnWithImageName:(NSString *)imageName{
    
    UIButton *btn = [[UIButton alloc]init];
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    
    [btn sizeToFit];
    
    return [[UIBarButtonItem alloc]initWithCustomView:btn];
    
}


+( instancetype )setupNavBarBtnWithTitle:(NSString *)title andTarget:(id)target action:(SEL)action{
    
    UIButton *btn = [[UIButton alloc]init];
    
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:title];
    NSRange strRange = {0,[str length]};
    
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:strRange];
    
    
    [str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:strRange];
    [btn setAttributedTitle:str forState:UIControlStateNormal];
    
    
    [btn setTitle:title forState:UIControlStateNormal];
    
    [btn sizeToFit];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return  [[UIBarButtonItem alloc]initWithCustomView:btn];
    
    
}



@end
